<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>百日新高</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script>
		<script>
			var dt = "";
			var tt = "";
			var gt = "";
			var k = "0";
			window.onload = function() {
			var day = new Date();
			gt = day.getTime();
			mymonth = day.getMonth()+1;
			myday = day.getDate();
			if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
			if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
			tt = day.getFullYear() + "-" + mymonth + "-" + myday;	
			dt = tt;
			getSource();			
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {				
				//time_range("9:00","15:15")														
				},
				60000);
			})
			
			Date.prototype.Format = function (fmt) {
			var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
			};
			
			if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
						
												
			function cDayFunc(dp) 
			{ 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function BookingRmk(date){         
				tt = date;
				var date1 = new Date(tt);
				var date2 = new Date(dt);							
				k = 0;
				if(date1.getTime() < date2.getTime()){			
					k = 1;
					tradeday();
				}								
				getSource();						
			}

			function tradeday() {  //判断最后交易日
				var day = new Date(tt);							
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() - 24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					var url = "https://apphis.longhuvip.com/w1/api/index.php?a=GroupStock&st=10&apiv=w26&Type=0_0_0_0_0&c=StockNewHigh&Date=" + tt;				
					var xhr = new XMLHttpRequest();	
					xhr.open("GET", url, false);//同步 
					xhr.send(null)																										
					var data = xhr.responseText;
					//document.write(data);
					if(data.indexOf('"GroupList":[]') == -1){						
						break;
					}
				}
			}				
			
			function createXmlHttp() {
				if (window.XMLHttpRequest) {
					xmlHttp = new XMLHttpRequest();					
					} else {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");					
				}
			}
			
			function getSource() {
				//alert(ss);
				div = document.getElementById('towrite');				
				div.innerHTML = '<font size="3">百日新高&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input style="width: 120px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';						
				
				var url1 = "https://apphq.longhuvip.com/w1/api/index.php?a=GroupStock&st=1000&apiv=w26&Type=0_0_0_0_0&c=StockNewHigh&"; 								
				var url2 = "https://apphis.longhuvip.com/w1/api/index.php?a=GroupStock&st=1000&apiv=w26&Type=0_0_0_0_0&c=StockNewHigh&Date=" + tt + "&";				
				var url = url1;
				if(k == "1" )
				{
				  url = url2;
				}					
				createXmlHttp();
				xmlHttp.onreadystatechange = writeSource;
				xmlHttp.open("GET", url, true); 
				xmlHttp.send(null);				
			}
			
			function writeSource() {
			if (xmlHttp.readyState == 4) { 
				var data = xmlHttp.responseText
				//document.write(data);
				if(k == 0){
						tt = data.match(/"Date":"(\S*)","/)[1];
						dt = tt;
					}
				data = data.replace(/ /g,"");
				
				data = data.replace(/(\[\").*?(?=\])/g,function(word){ 
				str = word.match(/\[(\S*)/)[1];
				//str = word;
				return '{"code":' + str.split(',')[0] + 
				',"name":' + str.split(',')[1] +
				',"zf":' + str.split(',')[3] +
				',"bk":' + str.split(',')[4] + 
				',"zt":' + str.split(',')[10];});
				
				data = data.replace(/\[\[/g,'[{').replace(/\]\]/g,"}]").replace(/],{/g,"},{");
				//document.write(data);
				
				var transform_aa = [   						
				{"tag":"ul", children:function(){return(json2html.transform(this.GroupList, transform_bb));}}				
				];
				
				var id = "";
				var div1 = "";
				var i = 0;
				var transform_bb= 
				{"tag":"p", children:[
				{"tag":"ul", children:[												
				{"tag":"ul", children:function(){
					i = 0;
					id = this.GroupName;
					var name = "<a style='color:#fff;font-size:16px' href='javascript:void(0)' id='id" + id + "' onclick='update(\"" + id + "\")'>" + id + "</a>";									
					//return(name);
					div.innerHTML += "<p style='margin:1px;margin-left:5px;'>" + name + "</p>";
					var newDiv = document.createElement("div");
					newDiv.id = id;
					newDiv.style.display = "none";
					document.getElementById("towrite").appendChild(newDiv);
					div1 = document.getElementById(id);						
				}},				
				{"tag":"p", children:function(){return(json2html.transform(this.List, transform_cc));}}				
				]}]};
				
				var transform_cc= 
				{"tag":"ul", children:[
				{"tag":"ul", children:function(){
					i++;
					var gg = "<a style='font-size:14px' href='http://www.treeid/code_" + this.code + 
					"' onclick='changeCss(this,\"" + id + "\")'>" + this.code + 
					"&nbsp;&nbsp;" + this.name + " [" + this.zt + "]&nbsp;&nbsp;涨幅：" + 
					this.zf + "% &nbsp;&nbsp;板块：" + this.bk + "</a>";
					div1.innerHTML += "<li>" + gg.replace(/\[\]/g,"") + "</li>";
					aObj = document.getElementById('id' + id);	
					aObj.innerText = id + " (" + i + ")";
				}},									
				]};
				
				json2html.transform(data, transform_aa);
				//div.innerHTML = div.innerHTML + html;								
				}	
				document.getElementById("PriceDate").value = tt;
				temp = "";					
				$("div a:first").click();				
			}
			
			var temp = "";	
			function update(ss) {				
				if(document.getElementById(ss))
				{					
					div1 = document.getElementById(ss);
					if(temp.indexOf(ss) == -1)
					{
						temp += ss + ";";
						div1.style.display = "block";
					}
					else
					{
						temp = temp.replace(ss + ";" , "");
						div1.style.display = "none";
					}
				}											
			}
		</script>
	</head>
	<body>
		<div id="towrite"></div>
	</body>
</html>